package demo2;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-11
 * Time: 16:36
 */
public class TestDemo2 {

    //创建课缓存的线程池,超过所需线程,缓存后自动回收,线程数少,会创建线程
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newCachedThreadPool();
        for(int i =0;i<10;++i){
            int finalNum = i;
            threadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(finalNum+"次->线程名"+Thread.currentThread().getName());
                }
            });
        }
    }

}
